/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2014-10-13 14:51:37
 * @filename : static/logic/nmm/src/views/editAboutLookfor.tpl
 * @version : 
 * @description : 
 */

define(function(require, exports, module){

    var editAboutLookforView,
        mId = 'editAboutLookfor',reRender = false,menuName = 'editAboutLookfor',
        imglazyload = require('{component}imglazyload/zepto.imglazyload'),
        panel = require('{component}panel/zepto.panel'),
        tpl = require('{view}editAboutLookfor.tpl'),
        tplS = require('{view}selectMultiple.tpl'),
        tplN = require('{view}userNav.tpl');

    editAboutLookforView = Backbone.View.extend({

        template: _.template(tpl),
        templateN: _.template(tplN),
        templateS: _.template(tplS),

        bindEvt : function() {
            var tthis = this,dom=$('#'+mId);

            dom.find('.back').on('tap',function(e){
                window.location.href = '#myProfile/whole/custom1'; 
            });

            dom.find('.save').on('tap',function(e){
                var arr = dom.find('#relation').val(),
                    usr_id = userObj.account.usr_id;

                var value = 0; 
                    for (var i in arr) {
                        value += parseInt(arr[i]);
                    }

                //console.log(value);
                var callback = function(){
                    userObj.about.looking_for = value;
                    share.cacheUserInfo(usr_id,userObj);
                    window.location.href = '#myProfile/whole/custom1'; 
                }
                var obj = {relation : value};

                //console.log(obj);
                share.updateProfile(usr_id,callback,obj);
            });
        },      

        render: function (obj) {
            if (!share.checkPermission(true)){return;}; 
            share.reRender(reRender,mId); 
            userObj = share.getObjStorage(share.userInfo().usr_id);
            if ($('#'+mId).length < 1) { 
                $('body').append(this.template(lang));
                if ($('#userNav').length < 1) { 
                    $('body').append(this.templateN(lang));
                    panel.init(); 
                    $('#userNav').imglazyload({startY : 0,endY: $(window).height(),sW:50,sH:50}); 
                }
                this.bindEvt(); 
            } else {
                $('#'+mId).css('display','block');
            }

            share.panel(panel,this.templateN,mId,menuName);

            var arr=[],select = share.getLocalStorage('ms_relation');
           
            for (var i in select) { 
                 if(parseInt(parseInt(userObj.about.looking_for)&parseInt(select[i].value)) > 0) { 
                    arr.push(select[i].value);
                 }
            } 
         
            $('#'+mId).find('#relation').html(this.templateS({obj : select, arr:arr}));
        }

	});
	module.exports = editAboutLookforView;
})

